Modern computer run-time environments providing a fundamental set of services that all programs can use such as Java Standard Edition (Java SE) and Microsoft .NET Common Language Runtime (CLR), have adopted a form of access control based on stack inspection. When security is enabled, all security-sensitive resources are, by default, access restricted. Such resources include the file system, network, operating system, printers, etc. When access to a restricted resource is attempted, a particular security function is invoked by the underlying security system. For example, in Java SE, this function is called checkPermission( ), and in CLR, Demand( ). Both these functions take an object as a parameter that represents the access being attempted. For example, in Java SE, this object is of type Permission (of one of its subclasses) and in CLR this object is of type IPermission. The purpose of the functions is to traverse the stack of execution and verify that all the classes of all the methods on the stack have been granted the necessary authorization. If just one of the callers on the stack cannot exhibit the appropriate authorization, an Exception is thrown and access to the requested resource is denied to all the callers on the stack.
FIG. 4A shows a conventional stack inspection process 99 in Java SE, when the constructor of FileOutputStream is invoked. In the scenario of a stack inspection process 99 depicted in FIG. 4A, it is assumed that the main( ) method of a Client application invokes the FileOutputStream constructor to access file log.txt in write mode. The FileOutputStream constructor calls the checkWrite( ) method of the current SecurityManager (“sm”), passing to it the name of the file being accessed. The SecurityManager instance, sm, calls the checkPermission( ) method on sm with a Permission p of type FilePermission representing the right to access file log.txt in write mode. The checkPermission( ) method on sm, in turn, calls the static method AccessController.checkPermission( ) with the same parameter, p. This function performs the stack traversal backwards, verifying that all the callers on the stack (AccessController, SecurityManager, FileOutputStream, and Client) have been granted Permission “p” (or a Permission stronger than p, for example the FilePermission to read and write all the files of the file system).
This architecture guarantees that if access to a protected resource succeeds, no untrusted code can be on the stack. This is particularly useful in systems where programs are collections of components, such as libraries, plug-ins, etc., (for example, Java Archive (JAR) files in Java SE or assembly files in CLR). In such systems, different components with different levels of trust may be assembled together, so it is important to ensure that untrusted components do not get unintended privileges.
Typically, permissions are fine grained. For example, for a Java SE FilePermission, it is possible to specify the name of the file(s) and the mode(s) of access (read, write, execute, and delete). Permissions are granted declaratively in an external policy file so that a computer programmer is not required to hardcode access control in a program.
Sometimes, trusted library code may need to perform certain operations that its callers did not explicitly request. For example, a library may exhibit a method, createSocket( ), responsible for constructing Sockets and returning them to its client programs. It makes sense to expect those client programs to be authorized with a SocketPermission. However, for auditing purposes, the library developer may have chosen to embed code in createSocket( ) that logs the Socket creation operation to a file. In this case, the library's client programs will need a FilePermission too. Since the purpose of createSocket( ) is to create a Socket, granting client programs the FilePermission to write to the log file would be a violation of the so called “Principle of Least Privilege” (see Jerome H. Saltzer and Michael D. Schroeder, “The Protection of Information in Computer Systems,” in Proceedings of the IEEE, Volume 63, Pages 1278-1308, September 1975). To prevent system administrators from needing to authorize client programs when a permission requirement is caused by a library, the portion of library code responsible for performing the operation not explicitly requested by the client can be made “privileged.” For example, in Java SE, making code privileged requires wrapping it into a call to doPrivileged( ) (see FIG. 4B); in CLR, it requires wrapping that code into a call to Assert( ). When authorization checks are performed, privileged code causes the stack inspection mechanism to interrupt at the library level. The end result is that client programs invoking that library will not be required to possess the permission to perform the operation executed in the library's privileged code.
This is particularly depicted in FIG. 4B which illustrates how client code, Client.main( ), invokes LibraryCode.createSocket( ) for the purpose of getting a socket connection to a remote system. When LibraryCode.createSocket( ) constructs the Socket, a stack 197 is generated that causes an authorization check. All the callers will need to prove possession of the necessary SocketPermission. However, in the example depicted, this library code has been programmed so that, as soon as the Socket has been created, the Socket creation is logged to a file. A new stack 198 is generated and all the callers on the stack will now have to prove possession of the necessary FilePermission. Fortunately, the developer has added a call 199 to doPrivileged( ), which stops the stack inspection at the frame just above doPrivileged( ). This way, the client code is exempted from proving possession of the FilePermission, and, consequently, the client code will not have to be granted any FilePermission to write to the log file log.txt. If the client had to be granted such permission, the client could misuse it and overwrite the log file. Since the library calls doPrivileged( ), it is not necessary for the client to have that FilePermission, and the client will not be able to misuse that permission.
Another form of access control adopted by modern computing systems is Role-Based Access Control (RBAC). For example, Java Enterprise Edition (Java EE) and CLR have adopted RBAC to restrict access to security-sensitive resources. In RBAC, restrictions are enforced on the operations performed by the code rather than the data manipulated by the code. A role is a semantic grouping of rights to access rights. Users of a RBAC system are assigned roles. When a user attempts to perform a restricted operation on an RBAC system, that user must have been authenticated and must show possessions of the roles necessary to perform that operation. Typically, the roles assigned to a user are propagated throughout the execution of the code. Therefore, stack inspection in these systems is not strictly necessary, since the roles granted to the executing user are immediately available to the underlying for verification, and there is no need to traverse the stack backwards. When access to a restricted operation is attempted, the underlying system verifies that the roles granted to the user are sufficient to perform that operation. Roles are typically granted declaratively in an external deployment descriptor file. This way, system administrators can configure access control of applications without the need for hardcoded access control.
Even though access control based on stack inspection and/or roles is very sophisticated, it is also very difficult to configure. Given a large and complex program, it becomes almost impossible to understand what permissions and/or roles are required before run time. Similarly, it is also very difficult to understand what portions of library code should be made privileged. The three approaches commonly used are:
1) Manual code inspection. This approach is extremely expensive and error prone. For large programs, this approach is discouraged. Additionally, the source code of the program may not be available (the compiled code could have been purchased from a third party or it could have been machine-generated), so this approach may not even be feasible;
2) Dynamic analysis or testing. This approach consists of writing or generating test cases that make calls into the target program. During testing, the system component responsible for enforcing security must be active. For example, in Java SE, there must be an active SecurityManager (which can be installed by specifying the -Djava.security.manager flag on the command line or by calling System.setSecurityManager(new SecurityManager( )) from within the program). The untrusted libraries or components should be granted no permissions. The trusted libraries should be granted AllPermission. At this point, executing a test case will generate security Exceptions every time access to a protected resource is attempted while untrusted code is on the stack. The tester is supposed to log each of these Exceptions, understand what permission is missing, decide whether it is appropriate to grant that permission, and, if yes, manually add that permission to the policy file (which is also a difficult operation since policy files have a complicated syntax, and a simple typo can make the entire policy not valid). If the code being tested is library code, it is also necessary to decide, for each missing permission, whether it is appropriate to require that client programs invoking that library be granted that permission or if it is more appropriate to make the portion of library code generating the permission requirement privileged. After a decision has been made, a new test case must be written and the same sequence of operations repeated until no security Exceptions are discovered. However, this process is tedious, time consuming, and error prone due to the following:                It is necessary to write or generate one or more test cases that cover each program entry point;        Additionally, a set of test cases is not guaranteed to be complete. Therefore, authorization requirements may remain undiscovered until run time;        For each Exception, it is necessary to inspect the stack trace, understand why the Exception was thrown, and identify where the permission was missing. If a permission should be granted, then it is also necessary to manually edit the policy file; and,        After an Exception has been processed (either by granting the required permission or by ignoring the permission requirement), it is necessary to restart the program.        
Typically, each security Exception generated during testing can terminate the program. It is therefore necessary to restart the program every time, and for complex program, it may be quite time consuming to bring them to a certain desired state where the testing can continue.
Additionally, dynamic analysis is potentially unsound, meaning that it may miss some authorization or privileged-code requirements because there may be paths of execution that may remain undiscovered during testing. For example, a particular path of execution for an application may become feasible only upon passing a certain parameter to one of the application's entry points. If that parameter is not passed to the application during testing, the corresponding path of execution may remain undiscovered until run time. Other errors might be performed while editing the policy file.
Static analysis. This approach consists of using a tool that models the execution of a program without running the program itself. From the model, it is possible to infer the program's authorization requirements (see Koved, Pistoia, Kershenbaum. Access Rights Analysis for Java. OOPSLA 2002, Seattle, November 2002) and the privileged code requirements (see Pistoia, Flynn, Koved, and Sreedhar. Interprocedural Analysis for Privileged Code Placement and Tainted Variable Detection. ECOOP 2005, Glasgow, Scotland, UK, July 2005). However, this approach too has some limitations:                Since static models must be very complex in order to report precise results, a static analysis tool may not scale to large programs.        Static analysis is conservative, which means that it may find authorization and privileged code requirements that are not real. Reasons for conservativeness include: path insensitivity, flow insensitivity, context insensitivity, etc. It can be mathematically proved that conservativeness cannot be completely removed.        Static analysis is not supposed to be unsound, but in reality it often is. For example, static analyzers for Java are able to analyze Java programs, but if a Java program causes (directly or indirectly) the execution of native methods (written in another language) or reflection, the analyzer typically does not show the control and data flows from the native methods. The model is incomplete and therefore, unsound.        Static analysis may require a very long time to complete (even days if fairly precise results are required).        
It is clear that none of these solutions alone is sufficient to completely determine the authorization requirements of a program.
It would be highly desirable to provide a system and method that performs automatic run-time discovery of authorization requirements.